#ifndef TRANSPORT_CTRL_LOGIC_H
#define TRANSPORT_CTRL_LOGIC_H
#define MyAbs(x)	(((x)>=0)?(x):(-x))
typedef struct
{
	union
	{
		UINT8 Bytes[1];
		struct
		{
			UINT8 fRelayFeedBack:1;
			UINT8 fWaterTemp:1;
			UINT8 fSafeEdge:1;	
			UINT8 fOilPressure:1;
			UINT8 Byte6_NC:4;
		}bit;
	}unDigitalInput;
	union 
	{
		UINT8 Bytes[6];
		struct
		{
			UINT16 u16TempSensor;	  //2
			UINT16 u16TempSensorP_FBK;//2
			UINT16 u16PumpRpm;			  //2
		}bit;
	}unAnalogInput;
}structTransportInput;
typedef struct
{
	union
	{
		UINT8 Bytes[2];
		struct
		{
			UINT8 fLeftOutValve:1;
			UINT8 fChargeRelay:1;
			UINT8 fStartRelay:1;
			UINT8 fStopHoldCtrl:1;
			UINT8 fWaterPumpRelay:1;
			UINT8 fOilPumpCtrl:1;
			UINT8 fPreHeatCtrl:1;
			UINT8 fHorn:1;
			
			UINT8 fLeftInValve:1;
			UINT8 fRightOutValve:1;
			UINT8 fMotionBeep:1;
			UINT8 fRightInValve:1;
			UINT8 fLampCtrl:1;
			UINT8 Byte1NC:3;
		}bit;
	}unDigitalOutput;
	union
	{
		UINT8 Bytes[1];
		struct
		{
			UINT8 u8TempSeneorP;
			
		}bit;
	}unAnalogOutput;
}structTransportOutput;
extern structTransportInput stTransportInput;
extern structTransportOutput stTransportOutput;
extern void vPorcCtrlLogic(void);//1ms
extern void vInitStreerSlope(void);

///////////////////////////////////////////////////////
//斜坡
#define SpeedParaRato						(10)//
typedef struct
{
	INT8 s8OutValue;
	INT16 s16OutValue_X10;//跟随输出值*10
	UINT16 u16StartSlope;
	UINT16 u16StopSlope;
}tSlope;//泵电机斜率处理
extern tSlope stStreerSlope;
extern void vSlope(tSlope *pSlope,INT8 s8Ref,UINT8 u8Cmd);
extern UINT16 vSlope_ms_to_Deta(UINT16 u16Slope_ms_X10,UINT16 u16SpeedPercent,UINT8 u8SlopeCallCycle);
//角度积分
#define MaxStreerAngleX1000	(60000)
#define MinStreerAngleX1000	(-60000)

typedef struct
{
	INT32 Angle_X1000; // 角度值
	INT16 Angle_X10; // 角度值
}structStreerAngle;
extern structStreerAngle stStreerAngle;
extern void vProcStreerAngle(structStreerAngle *pStreerAngle,INT8 s8Speed,UINT8 u8Cmd);
extern void vInitStreerAngle(void);
//////////////////////////////////
extern void vProcAngleCaculate(void);
extern void vProcStreer(void);//20ms//角度计算5ms

/*
	转向控制
*/
#define ProcStreerCycleTime	(20)
#define ReturnToZeroTime	(10000/ProcStreerCycleTime)//10s 500
#define ReturnToZeroTimeMin	(20/ProcStreerCycleTime)//20ms 
typedef enum
{
    WalkModeIdle = 0,       // 空闲模式，设备处于静止状态
    WalkModeFrontStreer,    // 前轮转向模式，仅前轮参与转向
    WalkModeRearStreer,     // 后轮转向模式，仅后轮参与转向
    WalkModeFrontRearStreer,// 前后轮转向模式，前后轮同时参与转向
    WalkModeParallelogram,  // 平行四边形模式，特殊的转向模式，可能用于特定场景
    WalkModeHorizontal,     // 横向移动模式，设备可横向移动
    WalkModeRotation,       // 旋转模式，设备可原地旋转
    WalkModeErr,            // 错误模式，表示行走模式异常
}enumWalkMode;
typedef struct
{
	enumWalkMode enWalkMode;
	enumWalkMode enWalkModeLast;
	UINT16 u16StateInCnt;
	UINT16 u16UserCnt;
	float SpeedPerFrontLeft; // 前左轮速度
	float SpeedPerFrontRight; // 前右轮速度
	float SpeedPerRearLeft; // 后左轮速度
	float SpeedPerRearRight; // 后右轮速度
	float TotalTheta;//内圈轮给定角度
	float Theta2;//外圈轮给定角度
	INT16 s16AngleFrontLeft; // 前左轮角度
	INT16 s16AngleFrontRight; // 前右轮角度
	INT16 s16AngleRearLeft; // 后左轮角度
	INT16 s16AngleRearRight; // 后右轮角度
	UINT8 fModeChangeOk:1;//
}structMovementCtrl;
extern structMovementCtrl stMovementCtrl;
/*行走*/
typedef struct
{
	INT16 s16FrontLeftSpeed; // 前左轮速度
	INT16 s16FrontRightSpeed; // 前右轮速度
	INT16 s16RearLeftSpeed; // 后左轮速度
	INT16 s16RearRightSpeed; // 后右轮速度
}structSpeedCtrl;
extern structSpeedCtrl stSpeedCtrl;
extern tSlope stWalkSlope;
extern void vProcWalk(void);
extern void vInitWalkSlope(void);

/**
 * 转向初始化
 */
void vStreerAction_Init();


#endif
